package com.flx.multi.thread.local;

/**
 * @Author Fenglixiong
 * @Create 2021/12/5 23:27
 * @Description
 *
 * 下面程序会爆空指针异常
 * 因为get方法返回long，涉及到拆包
 **/
public class ThreadLocalTest {

    public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
    public static ThreadLocal<Long> threadLocal2 = new ThreadLocal<>();

    public static void set(){
        threadLocal.set(1L);
    }

    public static long get(){
        return threadLocal.get();
    }

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            set();
            System.out.println(get());
        }).start();
        Thread.sleep(1000);
        System.out.println(threadLocal2.get());
        System.out.println(get());
    }

}
